package com.jingdianjichi.subject.domain.handler.Subject;

import com.jingdianjichi.subject.common.enums.IsDeleteFlagEnum;
import com.jingdianjichi.subject.common.enums.SubjectTypeEnums;
import com.jingdianjichi.subject.domain.convert.MultipleSubjectConverter;
import com.jingdianjichi.subject.domain.entity.SubjectAnswerBO;
import com.jingdianjichi.subject.domain.entity.SubjectInfoBO;
import com.jingdianjichi.subject.domain.entity.SubjectOptionBo;
import com.jingdianjichi.subject.infra.basic.entity.SubjectMultiple;
import com.jingdianjichi.subject.infra.basic.service.SubjectMultipleService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * 多选策略类
 */
@Component

public class MultipleTypeHandler implements SubjectTypeHandler{

    @Resource
    private SubjectMultipleService  subjectMultipleService;
    @Override
    public void add(SubjectInfoBO subjectInfobo) {
        List<SubjectMultiple> multipleList=new ArrayList<>();
        List<SubjectAnswerBO> optionList = subjectInfobo.getOptionList();
        optionList.forEach(option->{
            SubjectMultiple subjectMultiple=new SubjectMultiple();
            subjectMultiple=MultipleSubjectConverter.INSTANCE.convertBoToInfo(option);
            subjectMultiple.setSubjectId(subjectInfobo.getId());
            subjectMultiple.setIsDeleted(IsDeleteFlagEnum.UN_DELETED.getCode());
            multipleList.add(subjectMultiple);
        });
        subjectMultipleService.insertBatch(multipleList);

    }

    @Override
    public SubjectTypeEnums getSubjectType() {
        return  SubjectTypeEnums.MULTIPLE;
    }
    @Override
    public SubjectOptionBo query(Long id) {
        return null;
    }
}
